﻿namespace USElections.Tiles
{
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using USElections.Model;

    public partial class CalendarBackTile : UserControl
    {
        public CalendarBackTile()
        {
            InitializeComponent();

            var collection = Data.Instance.CalendarItems.NextItemsOnTheCalendar;

            if (collection != null)
            {
                this.Next = collection.First();
            }

            this.DataContext = this;
        }

        public CalendarItem Next
        {
            get;
            private set;
        }

        public string StartDate
        {
            get
            {
                if (this.Next != null)
                {
                    return this.Next.StartDate.ToString("MMM d, yyyy");
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        public Visibility IsMoreVisibile
        {
            get
            {
                if (Data.Instance.CalendarItems.NextItemsOnTheCalendar != null)
                {
                    var count = Data.Instance.CalendarItems.NextItemsOnTheCalendar.Count();
                    
                    if (count > 1)
                    {
                        return System.Windows.Visibility.Visible;
                    }
                }

                return System.Windows.Visibility.Collapsed;
            }
        }

        public int Count
        {
            get
            {
                if (Data.Instance.CalendarItems.NextItemsOnTheCalendar != null)
                {
                    return Data.Instance.CalendarItems.NextItemsOnTheCalendar.Count();
                }

                return 0;
            }
        }
    }
}
